<link href="/ast/layui/css/layui.css" rel="stylesheet">
<div class="layui-form" lay-filter="filter-test-layer" style="margin: 16px;">
            <div class="demo-login-container">
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                  <input type="text" id="cardname" value="" lay-verify="required" placeholder="用户名" lay-reqtext="name" autocomplete="off" class="layui-input" lay-affix="clear">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                  <input type="text" id="cardattack" value="" lay-verify="required" placeholder="用户密码" lay-reqtext="attack" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
              <div class="layui-form-item">
                <div class="layui-input-wrap">
                  <input type="text" id="cardurl" value="" lay-verify="required" placeholder="用户邮箱" lay-reqtext="url" autocomplete="off" class="layui-input" lay-affix="eye">
                </div>
              </div>
            
              <div class="layui-form-item">
                <button class="layui-btn layui-btn-fluid" id='button-add'  lay-submit lay-filter="addcard">Add</button>
              </div>
             
            </div>
          </div>
          <script src="/ast/layui/layui.js"></script>
<script>
layui.use('form', function(){
  var form = layui.form;
  var layer = layui.layer;
  form.render();
  return false;
});
function fetchcardadd(){
    const card_name = document.getElementById('cardname').value;
    const card_attack = document.getElementById('cardattack').value;
    const card_url = document.getElementById('cardurl').value;
    if(card_name === '' || card_attack === '' || card_url === ''){
        layer.msg('请填写完整信息', {icon: 5});
        return false;
    }
    var loadingz = layer.load(2);
    fetch('ht/adduser.php?name='+card_name+'&attack='+card_attack+'&url='+card_url)
    .then(response => response.json())
    .then(data => {
        layer.close(loadingz);
        if(data.code === 1){
            layer.msg(data.msg, {icon: 6});
        }else{
            layer.msg('添加失败'+data.msg, {icon: 5});
        }
        setTimeout(function(){
            window.location.reload();
        }, 1000);
    })
}
document.getElementById('button-add').addEventListener('click', fetchcardadd)
</script>